<?php

class Login extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->model('login_auth');
		$this->load->model('admin_m');
	}
	function index(){
		
		$this->load->view('login');
		
	}
	
	function _add_session($data){
		
		$session = array(
			'username' => $data->email
		);
		
		$this->session->set_userdata($session);
		redirect('accounts');
	}
	function authenticate(){
		
		$res = $this->login_auth->auth();
		
		if($res == false){
			redirect('login/?error=1');
		}
		else{
			$this->_add_session($res);
		}
		
		
	}
	/* admin side */
	function admin(){
		$data = array(
			'title' => 'Admin | Login'
		);
		
		$this->load->view('admin/login');
	}
	function auth_admin(){
		
		$res = $this->admin_m->admin_auth();
		
		if($res == false){
			redirect('login/admin/?error=1');
		}
		else{
			$this->_add_session_admin($res);
		}
	
		
	}// end authenticate..
	function _add_session_admin($data){
		
		$session = array(
			'admin_id' => $data->id
		);
		$this->session->set_userdata($session);
		redirect('admin');
	}// end add session..
	
}// end login